public class BankAccount {
    // 私有属性，外部不能直接访问
    private String accountNumber;
    private double balance;
    private String owner;
    
    // 构造方法
    public BankAccount(String accountNumber, String owner, double initialBalance) {
        this.accountNumber = accountNumber;
        this.owner = owner;
        this.balance = initialBalance;
    }
    
    // 公共方法，提供对属性的受控访问
    public void deposit(double amount) {
        if (amount > 0) {
            balance += amount;
            System.out.println("存款成功，当前余额: " + balance);
        } else {
            System.out.println("存款金额必须大于0");
        }
    }
    
    public void withdraw(double amount) {
        if (amount > 0 && amount <= balance) {
            balance -= amount;
            System.out.println("取款成功，当前余额: " + balance);
        } else {
            System.out.println("取款失败，余额不足或金额无效");
        }
    }
    
    // 只提供getter，不提供setter，保护数据
    public double getBalance() {
        return balance;
    }
    
    public String getAccountNumber() {
        return accountNumber;
    }
    
    public String getOwner() {
        return owner;
    }
    
    public void displayAccountInfo() {
        System.out.println("账户: " + accountNumber + ", 户主: " + owner + ", 余额: " + balance);
    }
}
